import 'package:flutter/material.dart';
import 'package:chatroom_flutter_app/ui/page/recommend_page.dart';
import 'package:chatroom_flutter_app/ui/page/square_page.dart';
import 'package:chatroom_flutter_app/ui/page/chat_page.dart';
import 'package:chatroom_flutter_app/ui/page/im_page.dart';
import 'package:chatroom_flutter_app/ui/page/mine_page.dart';

import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../widget/bar_item_svga_icon.dart';


class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  List<Widget> pages = [const ChatPage(), const SquarePage(), const RecommendPage(), const ImPage(),const MinePage()];
  int _currentIndex = 0;

  BottomNavigationBarItem barItem(String title,String defUrl,String assetsUrl,int index){
    return  BottomNavigationBarItem(
        label:title,
        icon: SizedBox(
          width: 30.r,
          height: 30.r,
          child: Image.asset(defUrl),
        ),
        activeIcon:SizedBox(
          width: 30.r,
          height: 30.r,
          child: BarItemSvgaIcon(assetsUrl: assetsUrl,repeat: index == 2),
        ),
    );
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: pages[_currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        showUnselectedLabels: true,
        unselectedItemColor: const Color(0XFF8F98C5),
        selectedItemColor: const Color(0XFFFF6691),
        unselectedFontSize:10.sp,
        selectedFontSize: 10.sp,
        currentIndex: _currentIndex,
        onTap: (int index){
          setState(() {
            _currentIndex = index;
          });
        },
        items: [
          barItem('聊天室','./assets/images/icon_tab_chat.png','./assets/images/icon_tab_chat.svga',0),
          barItem('广场','./assets/images/icon_tab_square.png','./assets/images/icon_tab_square.svga',1),
          barItem('推荐','./assets/images/icon_tab_recommend.png', './assets/images/icon_tab_recommend.svga',2),
          barItem('聊天','./assets/images/icon_tab_im.png','./assets/images/icon_tab_im.svga',3),
          barItem('我的','./assets/images/icon_tab_mine.png','./assets/images/icon_tab_mine.svga',4)
        ],
      ),
    );
  }
}
